package com.bigger.config;

import com.bigger.constant.MqConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {

    /**
     * 定义topic交换机
     * @return
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(MqConstant.XHDN_EXCHANGE,true,false);
    }

    /**
     * 定义新增或修改队列
     * @return
     */
    @Bean
    public Queue insertQueue(){
        return new Queue(MqConstant.XHDN_INSERT_QUEUE,true);
    }

    /**
     * 定义删除队列
     * @return
     */
    @Bean
    public Queue deleteQueue(){
        return new Queue(MqConstant.XHDN_DELETE_QUEUE,true);
    }

    @Bean
    public Binding insertBinding(){
        return BindingBuilder.bind(insertQueue()).to(topicExchange()).with(MqConstant.XHDN_INSERT_KEY);
    }

    @Bean
    public Binding deleteBinding(){
        return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with(MqConstant.XHDN_DELETE_KEY);
    }
}
